#!/bin/bash

# 获取当前目录的绝对路径
CURRENT_DIR=$(pwd)

# 从 PATH 中移除当前目录
echo "从 PATH 中移除 build.sh 所在目录"
export PATH=$(echo "$PATH" | sed -e "s|:${CURRENT_DIR}||" -e "s|${CURRENT_DIR}:||" -e "s|${CURRENT_DIR}||")

# 移除永久导出的内容
SHELL_CONFIG=""
if [ -n "$ZSH_VERSION" ]; then
    SHELL_CONFIG="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ]; then
    SHELL_CONFIG="$HOME/.bashrc"
fi

if [ -n "$SHELL_CONFIG" ]; then
    sed -i "/${CURRENT_DIR}/d" "${SHELL_CONFIG}"
    echo "PATH 永久配置已更新，请重新启动终端或运行 'source ${SHELL_CONFIG}'"
else
    echo "无法确定 shell 配置文件，反导出仅对当前会话有效"
fi
